package me.youline.dataServer.service.socialAction.handler;

import org.springframework.util.Assert;

import me.youline.dataServer.entity.UserBaseInfo;
import me.youline.dataServer.service.support.MobilePushService;

import com.notnoop.apns.APNS;

/**
 * 手机通知栏消息推送辅助业务类，为社交行为通知提供了基本的通知模板，只要传入指定格式数据就会生成有效的推送消息。
 * @author linhan
 *
 */
public class MobilePushHelper {

	private  final UserBaseInfo initiator;
	
	private final String format;
	
	private final int badage;
	
	private final Long notifiedUserId;
	
	private static final String DEFAULT_TITLE = "由来通知";
	
	
	public MobilePushHelper(UserBaseInfo initiator, String format, int badage,
			Long notifiedUserId) {
		Assert.notNull(initiator,"事件发起人信息不得为空");
		this.initiator = initiator;
		this.format = format;
		this.badage = badage;
		this.notifiedUserId = notifiedUserId;
	}

	public void doPublish(MobilePushService pushService){
		String payload = APNS.newPayload().alertTitle(DEFAULT_TITLE).alertBody(String.format(format, initiator.getNickName())).badge(badage).sound("chime.aiff").build();
		pushService.push(notifiedUserId, payload);
	}
	
}
